﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace ServiceBase
{
    /// <summary>
    /// 将Bitmap转换为二维数组
    /// </summary>
    public static class Bitmap2Array
    {
        public static bool[,] ToBool(Bitmap bmp)
        {
            bool[,] table = new bool[bmp.Width, bmp.Height];
            for (int i = 0; i < bmp.Width; i++)
                for (int j = 0; j < bmp.Height; j++)
                {
                    Color c = bmp.GetPixel(i, j);
                    if (c == Color.Black)
                        table[i, j] = true;
                }
            return table;
        }

        public static int[,] ToNum(Bitmap bmp)
        {
            int[,] table = new int[bmp.Width, bmp.Height];
            for (int i = 0; i < bmp.Width; i++)
                for (int j = 0; j < bmp.Height; j++)
                {
                    Color c = bmp.GetPixel(i, j);
                    if (c == Color.Black)
                        table[i, j] = 1;
                }
            return table;
        }

        public static Color[,] ToColor(Bitmap bmp)
        {
            Color[,] table = new Color[bmp.Width, bmp.Height];
            for (int i = 0; i < bmp.Width; i++)
                for (int j = 0; j < bmp.Height; j++)
                {
                    table[i, j] = bmp.GetPixel(i, j);
                }
            return table;
        }
    }
}
